package com.ruoyi.category.controller;


import com.repair.api.category.request.param.ServiceCategoryDeleteParam;
import com.repair.api.category.request.param.ServiceCategoryGetParam;
import com.repair.api.category.request.param.ServiceCategorySaveParam;
import com.repair.api.category.response.data.CategoryInfo;
import com.repair.base.result.JsonResult;
import com.ruoyi.category.service.AdminCategoryService;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "类别管理模块")
@RestController
@RequestMapping("/admin/category")
public class AdminCategoryController {
    @Autowired
    private AdminCategoryService adminCategoryService;
    @ApiOperation("查询全部服务分类")
    @GetMapping("getAllPrimaryCategories")
    public R<List<CategoryInfo>> getAllPrimaryCategory(ServiceCategoryGetParam serviceCategoryGetParam){
        List<CategoryInfo> allCategories = adminCategoryService.getAllCategories(serviceCategoryGetParam);
        return R.ok(allCategories);
    }
    @ApiOperation("新增或更新服务分类")
    @PostMapping("/save")
    public R<String> saveOrUpdateCategory(@RequestBody ServiceCategorySaveParam serviceCategorySaveParam) {
        adminCategoryService.save(serviceCategorySaveParam);
        return R.ok("保存成功");
    }
    @ApiOperation("删除服务分类")
    @PostMapping("/delete")
    public R<String> deleteCategoryById(@RequestBody ServiceCategoryDeleteParam serviceCategoryDeleteParam) {
        adminCategoryService.delete(serviceCategoryDeleteParam);
        return R.ok("删除成功");
    }
}
